commonController = function(){
    this.portfolio_count=0;
    // **************** ON LOAD ACTIONS
    this.onLoadActions = function() {
        $('a').click(function(){
            $(this).blur();
        });
        commonController.initHints('.hint');
        $('.hint').live('focus',function(){
            value = $(this).attr('title');
            $(this).val('');
            $(this).removeClass('hint');
            $(this).addClass('hinted');
            $(this).blur(function(){
                if(!$(this).val().length) {
                    $(this).val(value);
                    $(this).addClass('hint');
                    $(this).removeClass('hinted');
                }
            });
        });
        $('.hinted').live('blur', function() {
            if(!$(this).val().length) {
                value = $(this).attr('title');
                $(this).val(value);
                $(this).addClass('hint');
                $(this).removeClass('hinted');
            }
        })
        this.replaceFont();
    };
    this.replaceFont=function(){
                Cufon.replace('.title-blog a, .title-blog2 a, .title-comments  a , .title-solution  a, .title-about  a, .title-team a, .title-aboutteam  a, .title-contacts a, .title-websites a, .title-portfolio-web a, .title-web a, .title-reviews a, .title-order a, .title-text a, .contacts, .team-bigpic h3.team_text, .content_bottom .bold_name, .blog-read-comments p, .pic h3.blog_text, .contacts-form h3', {fontFamily: 'arial black'});
    }
    // **************** ALERTS
    
    this.showErrorMessage = function(error_array) {
        message = '';
        $.each(error_array,function(i, val){
            message = message + i + ': ' + val +'\n';
        });
        alert(message);
    };
    this.showSuccessMessage = function(message) {
        alert(message);
    };
    this.showConnectionError = function() {
        var error = {};
        error[msgs['Connection error']] = msgs['Connection error explain'];
        commonController.showErrorMessage(error);
    }
    
    // **************** HINTS
    
    this.initHints = function(selector) {
        $(selector).each(function(){
            if(!$(this).val().length) {
                $(this).val($(this).attr('title'));
            } else {
                $(this).removeClass('hint');
                $(this).addClass('hinted');
            }
        })
    };
    
    // **************** LOADER
    
    this.loader_html = '<div class="loader-wrapper" style="display: none;"><div class="loader"></div></div>';
    this.showLoader = function(selector) {
        if(!$(selector).length) return false;
        $(selector).addClass('loader-transparent');
        var loader = $(selector).find('.loader-wrapper');
        if(!$(loader).size()) loader = $(selector).prepend(this.loader_html).find('.loader-wrapper');
        var height = $(selector).height() + $(selector).css('padding-top').replace('px','')*1 + $(selector).css('padding-bottom').replace('px','')*1;
        var width = $(selector).width() + $(selector).css('padding-left').replace('px','')*1 + $(selector).css('padding-right').replace('px','')*1;
        loader.height(height);
        loader.width(width);
        loader.css('margin-top', '-'+$(selector).css('padding-top'));
        loader.css('margin-left', '-'+$(selector).css('padding-left'));
        loader.find('.loader').css('margin-top', (height-16)/2);
        loader.show();
        return loader;
    };
    this.hideLoader = function(selector) {
        $(selector).removeClass('loader-transparent');
        var loader = $(selector).find('.loader-wrapper');
        $(loader).remove();
    };
    
    // **************** UTILS
    
    this.toUrlString = function(obj, prefix) {
        var str = [];
        for(var p in obj) {
            var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
            str.push(typeof v == "object" ?
                this.toUrlString(v, k) :
                encodeURIComponent(k) + "=" + encodeURIComponent(v));
        }
        return str.join("&");
    }
    this.slideTab=function(position){
        this.current_tab=$('.tab_conainer:visible');
        this.number=this.current_tab.attr('id');
        this.current_id=this.number;
        switch(position){
            case 'left':
                --this.number;
                this.number=this.number<1?this.portfolio_count:this.number;
                break;
            case 'right':
                ++this.number;
                this.number=this.number>this.portfolio_count?1:this.number;
                break;
                
        }
        this.current_tab.hide(500);
        $('#portfolio_'+this.current_id).hide(500);
        $('#portfolio_'+this.number).show(500)
        $('#'+this.number).show(500);
        return false;
    }
};

var commonController = new commonController();
$(document).ready(function(){
    commonController.onLoadActions();
    setInterval("commonController.slideTab('left')", 5000 );
});